home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 January: Mac OS SDK / Dev.CD Jan 00 SDK1.toast / Development Kits / Mac OS / QuickTime / QuickTime 3 Interfaces & Libs / QTDevWin / CIncludes / Threads.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-21  |  10.3 KB  |  290 lines  |  [TEXT/dosa]

  1. /*
  2.      File:        Threads.h
  3.  
  4.      Contains:    Thread Manager Interfaces.
  5.  
  6.      Version:    Technology:    Mac OS 8
  7.                  Release:    QuickTime 3.0
  8.  
  9.      Copyright:    © 1991-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __THREADS__
  19. #define __THREADS__
  20.  
  21. #ifndef __MACTYPES__
  22. #include <MacTypes.h>
  23. #endif
  24. #ifndef __MIXEDMODE__
  25. #include <MixedMode.h>
  26. #endif
  27. #ifndef __ERRORS__
  28. #include <Errors.h>
  29. #endif
  30.  
  31.  
  32.  
  33. #if PRAGMA_ONCE
  34. #pragma once
  35. #endif
  36.  
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40.  
  41. #if PRAGMA_IMPORT
  42. #pragma import on
  43. #endif
  44.  
  45. #if PRAGMA_STRUCT_ALIGN
  46.     #pragma options align=mac68k
  47. #elif PRAGMA_STRUCT_PACKPUSH
  48.     #pragma pack(push, 2)
  49. #elif PRAGMA_STRUCT_PACK
  50.     #pragma pack(2)
  51. #endif
  52.  
  53. /* Thread states */
  54. typedef unsigned short                     ThreadState;
  55.  
  56. enum {
  57.     kReadyThreadState            = 0,
  58.     kStoppedThreadState            = 1,
  59.     kRunningThreadState            = 2
  60. };
  61.  
  62. /* Error codes have been meoved to Errors.(pah) */
  63. /* Thread environment characteristics */
  64. typedef void *                            ThreadTaskRef;
  65. /* Thread characteristics */
  66. typedef unsigned long                     ThreadStyle;
  67.  
  68. enum {
  69.     kCooperativeThread            = 1L << 0,
  70.     kPreemptiveThread            = 1L << 1
  71. };
  72.  
  73. /* Thread identifiers */
  74. typedef unsigned long                     ThreadID;
  75.  
  76. enum {
  77.     kNoThreadID                    = 0,
  78.     kCurrentThreadID            = 1,
  79.     kApplicationThreadID        = 2
  80. };
  81.  
  82. /* Options when creating a thread */
  83. typedef unsigned long                     ThreadOptions;
  84.  
  85. enum {
  86.     kNewSuspend                    = (1 << 0),
  87.     kUsePremadeThread            = (1 << 1),
  88.     kCreateIfNeeded                = (1 << 2),
  89.     kFPUNotNeeded                = (1 << 3),
  90.     kExactMatchThread            = (1 << 4)
  91. };
  92.  
  93. /* Information supplied to the custom scheduler */
  94.  
  95. struct SchedulerInfoRec {
  96.     unsigned long                     InfoRecSize;
  97.     ThreadID                         CurrentThreadID;
  98.     ThreadID                         SuggestedThreadID;
  99.     ThreadID                         InterruptedCoopThreadID;
  100. };
  101. typedef struct SchedulerInfoRec            SchedulerInfoRec;
  102. typedef SchedulerInfoRec *                SchedulerInfoRecPtr;
  103.  
  104. #if TARGET_CPU_68K && TARGET_RT_MAC_CFM
  105. /*
  106.     The following UniversalProcPtrs are for CFM-68k compatiblity with
  107.     the implementation of the Thread Manager.
  108. */
  109.  
  110. typedef UniversalProcPtr                 ThreadEntryProcPtr;
  111. typedef UniversalProcPtr                 ThreadSchedulerProcPtr;
  112. typedef UniversalProcPtr                 ThreadSwitchProcPtr;
  113. typedef UniversalProcPtr                 ThreadTerminationProcPtr;
  114. typedef UniversalProcPtr                 DebuggerNewThreadProcPtr;
  115. typedef UniversalProcPtr                 DebuggerDisposeThreadProcPtr;
  116. typedef UniversalProcPtr                 DebuggerThreadSchedulerProcPtr;
  117. enum {
  118.     uppThreadEntryProcInfo = kPascalStackBased
  119.          | RESULT_SIZE(SIZE_CODE(sizeof(void*)))
  120.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(void*))),
  121.     uppThreadSchedulerProcInfo = kPascalStackBased
  122.          | RESULT_SIZE(SIZE_CODE(sizeof(ThreadID)))
  123.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SchedulerInfoRecPtr))),
  124.     uppThreadSwitchProcInfo = kPascalStackBased
  125.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ThreadID)))
  126.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(void*))),
  127.     uppThreadTerminationProcInfo = kPascalStackBased
  128.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ThreadID)))
  129.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(void*))),
  130.     uppDebuggerNewThreadProcInfo = kPascalStackBased
  131.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ThreadID))),
  132.     uppDebuggerDisposeThreadProcInfo = kPascalStackBased
  133.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ThreadID))),
  134.     uppDebuggerThreadSchedulerProcInfo = kPascalStackBased
  135.          | RESULT_SIZE(SIZE_CODE(sizeof(ThreadID)))
  136.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SchedulerInfoRecPtr)))
  137. };
  138. #define NewThreadEntryProc(userRoutine)                (ThreadEntryProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppThreadEntryProcInfo, GetCurrentArchitecture())
  139. #define NewThreadSchedulerProc(userRoutine)            (ThreadSchedulerProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppThreadSchedulerProcInfo, GetCurrentArchitecture())
  140. #define NewThreadSwitchProc(userRoutine)            (ThreadSwitchProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppThreadSwitchProcInfo, GetCurrentArchitecture())
  141. #define NewThreadTerminationProc(userRoutine)        (ThreadTerminationProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppThreadTerminationProcInfo, GetCurrentArchitecture())
  142. #define NewDebuggerNewThreadProc(userRoutine)        (DebuggerNewThreadProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDebuggerNewThreadProcInfo, GetCurrentArchitecture())
  143. #define NewDebuggerDisposeThreadProc(userRoutine)    (DebuggerDisposeThreadProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDebuggerDisposeThreadProcInfo, GetCurrentArchitecture())
  144. #define NewDebuggerThreadSchedulerProc(userRoutine)    (DebuggerThreadSchedulerProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDebuggerThreadSchedulerProcInfo, GetCurrentArchitecture())
  145. #else
  146. /*
  147.     The following ProcPtrs cannot be interchanged with UniversalProcPtrs because
  148.     of differences between 680x0 and PowerPC runtime architectures with regard to
  149.     the implementation of the Thread Manager.
  150.  */
  151. /* Prototype for thread's entry (main) routine */
  152. typedef void *                            voidPtr;
  153. typedef CALLBACK_API( voidPtr , ThreadEntryProcPtr )(void *threadParam);
  154. /* Prototype for custom thread scheduler routine */
  155. typedef CALLBACK_API( ThreadID , ThreadSchedulerProcPtr )(SchedulerInfoRecPtr schedulerInfo);
  156. /* Prototype for custom thread switcher routine */
  157. typedef CALLBACK_API( void , ThreadSwitchProcPtr )(ThreadID threadBeingSwitched, void *switchProcParam);
  158. /* Prototype for thread termination notification routine */
  159. typedef CALLBACK_API( void , ThreadTerminationProcPtr )(ThreadID threadTerminated, void *terminationProcParam);
  160. /* Prototype for debugger NewThread notification */
  161. typedef CALLBACK_API( void , DebuggerNewThreadProcPtr )(ThreadID threadCreated);
  162. /* Prototype for debugger DisposeThread notification */
  163. typedef CALLBACK_API( void , DebuggerDisposeThreadProcPtr )(ThreadID threadDeleted);
  164. /* Prototype for debugger schedule notification */
  165. typedef CALLBACK_API( ThreadID , DebuggerThreadSchedulerProcPtr )(SchedulerInfoRecPtr schedulerInfo);
  166. #endif  /* TARGET_CPU_68K && TARGET_RT_MAC_CFM */
  167.  
  168.  
  169. /* Thread Manager routines */
  170. EXTERN_API( OSErr )
  171. CreateThreadPool                (ThreadStyle             threadStyle,
  172.                                  short                     numToCreate,
  173.                                  Size                     stackSize)                            THREEWORDINLINE(0x303C, 0x0501, 0xABF2);
  174.  
  175. EXTERN_API( OSErr )
  176. GetFreeThreadCount                (ThreadStyle             threadStyle,
  177.                                  short *                freeCount)                            THREEWORDINLINE(0x303C, 0x0402, 0xABF2);
  178.  
  179. EXTERN_API( OSErr )
  180. GetSpecificFreeThreadCount        (ThreadStyle             threadStyle,
  181.                                  Size                     stackSize,
  182.                                  short *                freeCount)                            THREEWORDINLINE(0x303C, 0x0615, 0xABF2);
  183.  
  184. EXTERN_API( OSErr )
  185. GetDefaultThreadStackSize        (ThreadStyle             threadStyle,
  186.                                  Size *                    stackSize)                            THREEWORDINLINE(0x303C, 0x0413, 0xABF2);
  187.  
  188. EXTERN_API( OSErr )
  189. ThreadCurrentStackSpace            (ThreadID                 thread,
  190.                                  unsigned long *        freeStack)                            THREEWORDINLINE(0x303C, 0x0414, 0xABF2);
  191.  
  192. EXTERN_API( OSErr )
  193. NewThread                        (ThreadStyle             threadStyle,
  194.                                  ThreadEntryProcPtr     threadEntry,
  195.                                  void *                    threadParam,
  196.                                  Size                     stackSize,
  197.                                  ThreadOptions             options,
  198.                                  void **                threadResult,
  199.                                  ThreadID *                threadMade)                            THREEWORDINLINE(0x303C, 0x0E03, 0xABF2);
  200.  
  201. EXTERN_API( OSErr )
  202. DisposeThread                    (ThreadID                 threadToDump,
  203.                                  void *                    threadResult,
  204.                                  Boolean                 recycleThread)                        THREEWORDINLINE(0x303C, 0x0504, 0xABF2);
  205.  
  206. EXTERN_API( OSErr )
  207. YieldToThread                    (ThreadID                 suggestedThread)                    THREEWORDINLINE(0x303C, 0x0205, 0xABF2);
  208.  
  209. EXTERN_API( OSErr )
  210. YieldToAnyThread                (void)                                                        FOURWORDINLINE(0x42A7, 0x303C, 0x0205, 0xABF2);
  211.  
  212. #if TARGET_OS_MAC
  213.     #define MacGetCurrentThread GetCurrentThread
  214. #endif
  215. EXTERN_API( OSErr )
  216. MacGetCurrentThread                (ThreadID *                currentThreadID)                    THREEWORDINLINE(0x303C, 0x0206, 0xABF2);
  217.  
  218. EXTERN_API( OSErr )
  219. GetThreadState                    (ThreadID                 threadToGet,
  220.                                  ThreadState *            threadState)                        THREEWORDINLINE(0x303C, 0x0407, 0xABF2);
  221.  
  222. EXTERN_API( OSErr )
  223. SetThreadState                    (ThreadID                 threadToSet,
  224.                                  ThreadState             newState,
  225.                                  ThreadID                 suggestedThread)                    THREEWORDINLINE(0x303C, 0x0508, 0xABF2);
  226.  
  227. EXTERN_API( OSErr )
  228. SetThreadStateEndCritical        (ThreadID                 threadToSet,
  229.                                  ThreadState             newState,
  230.                                  ThreadID                 suggestedThread)                    THREEWORDINLINE(0x303C, 0x0512, 0xABF2);
  231.  
  232. EXTERN_API( OSErr )
  233. SetThreadScheduler                (ThreadSchedulerProcPtr  threadScheduler)                    THREEWORDINLINE(0x303C, 0x0209, 0xABF2);
  234.  
  235. EXTERN_API( OSErr )
  236. SetThreadSwitcher                (ThreadID                 thread,
  237.                                  ThreadSwitchProcPtr     threadSwitcher,
  238.                                  void *                    switchProcParam,
  239.                                  Boolean                 inOrOut)                            THREEWORDINLINE(0x303C, 0x070A, 0xABF2);
  240.  
  241. EXTERN_API( OSErr )
  242. SetThreadTerminator                (ThreadID                 thread,
  243.                                  ThreadTerminationProcPtr  threadTerminator,
  244.                                  void *                    terminationProcParam)                THREEWORDINLINE(0x303C, 0x0611, 0xABF2);
  245.  
  246. EXTERN_API( OSErr )
  247. ThreadBeginCritical                (void)                                                        THREEWORDINLINE(0x303C, 0x000B, 0xABF2);
  248.  
  249. EXTERN_API( OSErr )
  250. ThreadEndCritical                (void)                                                        THREEWORDINLINE(0x303C, 0x000C, 0xABF2);
  251.  
  252. EXTERN_API( OSErr )
  253. SetDebuggerNotificationProcs    (DebuggerNewThreadProcPtr  notifyNewThread,
  254.                                  DebuggerDisposeThreadProcPtr  notifyDisposeThread,
  255.                                  DebuggerThreadSchedulerProcPtr  notifyThreadScheduler)        THREEWORDINLINE(0x303C, 0x060D, 0xABF2);
  256.  
  257. EXTERN_API( OSErr )
  258. GetThreadCurrentTaskRef            (ThreadTaskRef *        threadTRef)                            THREEWORDINLINE(0x303C, 0x020E, 0xABF2);
  259.  
  260. EXTERN_API( OSErr )
  261. GetThreadStateGivenTaskRef        (ThreadTaskRef             threadTRef,
  262.                                  ThreadID                 threadToGet,
  263.                                  ThreadState *            threadState)                        THREEWORDINLINE(0x303C, 0x060F, 0xABF2);
  264.  
  265. EXTERN_API( OSErr )
  266. SetThreadReadyGivenTaskRef        (ThreadTaskRef             threadTRef,
  267.                                  ThreadID                 threadToSet)                        THREEWORDINLINE(0x303C, 0x0410, 0xABF2);
  268.  
  269.  
  270. #if PRAGMA_STRUCT_ALIGN
  271.     #pragma options align=reset
  272. #elif PRAGMA_STRUCT_PACKPUSH
  273.     #pragma pack(pop)
  274. #elif PRAGMA_STRUCT_PACK
  275.     #pragma pack()
  276. #endif
  277.  
  278. #ifdef PRAGMA_IMPORT_OFF
  279. #pragma import off
  280. #elif PRAGMA_IMPORT
  281. #pragma import reset
  282. #endif
  283.  
  284. #ifdef __cplusplus
  285. }
  286. #endif
  287.  
  288. #endif /* __THREADS__ */
  289.  
  290.